import React from 'react';

import * as BillBoardAction  from '../../actions/BillboardAction';
import { connect }  from 'react-redux';

import AssetGridCell from '../assets/AssetGridCell'

import Paging from '../Paging'

export default class NewsPushList extends React.Component {
  constructor(props) {
    super(props);
  }

  componentDidMount() {
    this.$editModal = $(ReactDOM.findDOMNode(this.refs.NewsPushEdit))
    this.$assetModal = $(ReactDOM.findDOMNode(this.refs.MenuSettingAssetSelect))
  }

  componentDidUpdate(){
    var width = $('.News-setting-list').width();
    var imgHeight = (width*0.29-30)*0.56;
    $('.cell-image').css("height", imgHeight + "px");
  }

  renderList() {
    var self = this;

    var content = [];
    if (this.props.data && this.props.data.length > 0) {
      this.props.data.forEach(function(data, index) {
        var assetContent = data.content;
        var news_item = JSON.parse(assetContent)
        var news = news_item[0];
        var date = new Date(data.created_at);
        var dateFormat = date.getFullYear() + '年' + (date.getMonth()+1) + '月' + date.getDate() + '日'
        var assetData = {
          title: news.title,
          image: news.thumb_url,
          digest: news.digest,
          thumb_media_id: news.thumb_media_id,
          created_at: dateFormat
        }
        content.push((

          <AssetGridCell
            news = {data}
            data={assetData}
            disableHover = {true}
          />

        ))
      })
    }

    return content
  }

  render() {
    var self = this;
    // var data = this.props.data;
    var offset = parseInt(this.props.offset),
        limit = parseInt(this.props.limit),
        count = parseInt(this.props.count)
    var current = Math.ceil(offset/limit) + 1;
    return(
      <div className="News-setting-list setting-list ">
        <table className="table row">

          <tbody>
            {this.renderList()}

          </tbody>
        </table>

      </div>
    )
  }
}


// export default NewsPushList
